package com.ruoyi.web.controller.library;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.QzAbnormal;
import com.ruoyi.system.domain.ZlLibrary;
import com.ruoyi.system.mapper.QzAbnormalMapper;
import com.ruoyi.system.mapper.ZlLibraryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 前兆异常库
 * @author soulmate丶
 * @date 2021-08-23
 */
@RestController
@RequestMapping("/library/qzabnormal")
public class QzAbnormalController extends BaseController {

    @Autowired
    private QzAbnormalMapper qzAbnormalMapper;

    /**
     * 获取数据列表
     * @param qzAbnormal
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(QzAbnormal qzAbnormal){

        QueryWrapper<QzAbnormal> queryWrapper = new QueryWrapper<>();
        startPage();
        List<QzAbnormal> qzAbnormals = qzAbnormalMapper.selectList(null);
        return getDataTable(qzAbnormals);
    }

    /**
     * 获取一条recode
     * @param stationId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('library:zl:query')")
    @GetMapping(value = { "/", "/{zlId}" })
    public AjaxResult getInfo(@PathVariable(value = "zlId", required = false) String stationId)
    {
        AjaxResult ajax = AjaxResult.success();
        if (StringUtils.isNotNull(stationId))
        {
            QueryWrapper<QzAbnormal> queryWrapper = new QueryWrapper();
            queryWrapper.eq("id",stationId);
            ajax.put(AjaxResult.DATA_TAG, qzAbnormalMapper.selectOne(queryWrapper));
        }
        return ajax;
    }

    /**
     * 新增终端
     */
    @PreAuthorize("@ss.hasPermi('library:zl:add')")
    @Log(title = "前兆异常库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody QzAbnormal qzAbnormal)
    {
//        zlLibrary.setCreateTime();
        return toAjax(qzAbnormalMapper.insert(qzAbnormal));
    }


    /**
     * 修改震例库信息
     */
    @PreAuthorize("@ss.hasPermi('library:zl:edit')")
    @Log(title = "前兆异常库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody QzAbnormal qzAbnormal)
    {
        qzAbnormal.setUpdateBy(SecurityUtils.getUsername());
        qzAbnormal.setUpdateTime(DateUtils.getNowDate());
        return toAjax(qzAbnormalMapper.updateById(qzAbnormal));
    }

    /**
     * 删除一条记录
     */
    @PreAuthorize("@ss.hasPermi('library:zl:remove')")
    @Log(title = "前兆异常库管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{zlIds}")
    public AjaxResult remove(@PathVariable String zlIds)
    {
        return toAjax(qzAbnormalMapper.deleteById(zlIds));
    }

}
